<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
<head>
<title>Introduction to the Java Swing Toolkit</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Java, Swing, toolkit, programming, Introduction, 
tutorial, Linux, Windows, multiplatform">
<meta nam="description" content="This chapter is an introduction to the Java Swing Toolkit.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

</head>

<body>

<div class="container">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<div class="content">


<a href="/" title="Home">Home</a>&nbsp;
<a href=".." title="Home">Contents</a>


<h1>Introduction Java Swing</h1>


<p>
This is an introductory Swing tutorial. The purpose of this tutorial is to 
get you started with the Java Swing toolkit. The tutorial has been 
created and tested on Linux.
</p>

<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* NewSquare */
google_ad_slot = "0364418177";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script>

<h2>About Swing</h2>

<p>
Swing library is an official Java GUI toolkit released by Sun Microsystems. 
It is used to create Graphical user interfaces with Java. 
</p>

<p>
The main characteristics of the Swing toolkit
</p>

<ul>
<li>platform independent</li>
<li>customizable</li>
<li>extensible</li>
<li>configurable</li>
<li>lightweight</li>
</ul>

<p>
The Swing API has 18 public packages:
</p>

<ul>
<li>javax.accessibility</li>
<li>javax.swing</li>
<li>javax.swing.border</li>
<li>javax.swing.colorchooser</li>
<li>javax.swing.event</li>
<li>javax.swing.filechooser</li>
<li>javax.swing.plaf</li>
<li>javax.swing.plaf.basic</li>
<li>javax.swing.plaf.metal</li>
<li>javax.swing.plaf.multi</li>
<li>javax.swing.plaf.synth</li>
<li>javax.swing.table</li>
<li>javax.swing.text</li>
<li>javax.swing.text.html</li>
<li>javax.swing.text.html.parser</li>
<li>javax.swing.text.rtf</li>
<li>javax.swing.tree</li>
<li>javax.swing.undo</li> 
</ul>

<p>
Swing is an advanced GUI toolkit. It has a rich set of widgets. From 
basic widgets like buttons, labels, scrollbars to advanced widgets 
like trees and tables. Swing itself is written in Java. 
</p>

<p>
Swing is a part of JFC, Java Foundation Classes. It is a collection of 
packages for creating full featured desktop applications.
JFC consists of AWT, Swing, Accessibility, Java 2D, and Drag and Drop.
Swing was released in 1997 with JDK 1.2. It is a mature toolkit. 
</p>

<p>
The Java platform has Java2D library, which enables developers to create 
advanced 2D graphics and imaging. 
</p>

<p>
There are basically two types of widget toolkits. 
</p>

<ul>
<li>Lightweight</li>
<li>Heavyweight</li>
</ul>

<p>
A heavyweight toolkit uses OS's API to draw the widgets. For example Borland's 
VCL is a heavyweight toolkit. It depends on WIN32 API, the built in Windows 
application programming interface. On Unix systems, we have GTK+ toolkit, which 
is built on top of X11 library. Swing is a lightweight toolkit. It paints its own widgets. 
Similarly does the Qt4 toolkit. 
</p>

<h2>SWT library</h2>

<p>
There is also another GUI library for the Java programming language. It is 
called SWT. The Standard widget toolkit. The SWT library was initially 
developed by the IBM corporation. Now it is an open source project maintained
by the Eclipse community. The SWT is an example of a heavyweight toolkit. 
It lets the underlying OS to create GUI. SWT uses the java native interface 
to do the job. There is a <a href="/gui/javaswt/">tutorial</a> 
dedicated to SWT on ZetCode.
</p>


<p>
This was an introduction to Java Swing. 
</p>


<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified December 4, 2010  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>
